﻿//-----------------------------------------------------------------------
// <copyright file="ColumnAttribute.cs" company="LMT">
//     Copyright (c) by La Minh Thuận.
// </copyright>
// <author>thuanla1985@hotmail.com</author>
//-----------------------------------------------------------------------
namespace LMT.Db
{
    using System;
    using System.Data;

    /// <summary>
    /// An attribute for table colum information.
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
    public abstract class DbColumn : Attribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Column"/> class.
        /// </summary>
        /// <param name="colName">Name of the col.</param>
        /// <param name="dbType">Type of the OLE db.</param>
        /// <param name="colSize">Size of the col.</param>
        protected DbColumn(string colName, object dbType, ushort colSize)
        {
            this.ColumName = colName;
            this.DbType = dbType;
            this.ColumSize = colSize;
            this.IsParseUpdate = true;
            this.IsParseInsert = true;
            this.IsParseSelect = true;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Column"/> class.
        /// </summary>
        /// <param name="colName">Name of the col.</param>
        /// <param name="dbType">Type of the db.</param>
        /// <param name="colSize">Size of the col.</param>
        /// <param name="isPrimaryKey">if set to <c>true</c> [is primary key].</param>
        protected DbColumn(string colName, object dbType, ushort colSize, bool isPrimaryKey)
            : this(colName, dbType, colSize)
        {
            this.IsPrimaryKey = isPrimaryKey;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Column"/> class.
        /// </summary>
        /// <param name="colName">Name of the col.</param>
        /// <param name="oracle">Type of the OLE db.</param>
        /// <param name="colSize">Size of the col.</param>
        /// <param name="isPrimaryKey">if set to <c>true</c> [is primary key].</param>
        /// <param name="isUseSysDate">if set to <c>true</c> [is use database system date].</param>
        protected DbColumn(string colName, object dbType, ushort colSize, bool isPrimaryKey, bool isUseSysDate)
            : this(colName, dbType, colSize, isPrimaryKey)
        {
            this.IsUseSysDate = isUseSysDate;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Column"/> class.
        /// </summary>
        /// <param name="colName">Name of the col.</param>
        /// <param name="oracle">Type of the OLE db.</param>
        /// <param name="colSize">Size of the col.</param>
        /// <param name="isPrimaryKey">if set to <c>true</c> [is primary key].</param>
        /// <param name="isUseSysDate">if set to <c>true</c> [is use database system date].</param>
        /// <param name="isParseUpdate">if set to <c>true</c> [is parse update].</param>
        protected DbColumn(string colName, object dbType, ushort colSize, bool isPrimaryKey, bool isUseSysDate, bool isParseUpdate)
            : this(colName, dbType, colSize, isPrimaryKey, isUseSysDate)
        {
            this.IsParseUpdate = isParseUpdate;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Column"/> class.
        /// </summary>
        /// <param name="colName">Name of the col.</param>
        /// <param name="oracle">Type of the OLE db.</param>
        /// <param name="colSize">Size of the col.</param>
        /// <param name="isPrimaryKey">if set to <c>true</c> [is primary key].</param>
        /// <param name="isUseSysDate">if set to <c>true</c> [is use database system date].</param>
        /// <param name="isParseUpdate">if set to <c>true</c> [is parse update].</param>
        /// <param name="isUseDbSequence">if set to <c>true</c> [is use db sequence].</param>
        protected DbColumn(string colName, object dbType, ushort colSize, bool isPrimaryKey, bool isUseSysDate, bool isParseUpdate, bool isUseDbSequence)
            : this(colName, dbType, colSize, isPrimaryKey, isUseSysDate, isParseUpdate)
        {
            this.IsUseDbSequence = isUseDbSequence;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Column"/> class.
        /// </summary>
        /// <param name="colName">Name of the col.</param>
        /// <param name="oracle">Type of the OLE db.</param>
        /// <param name="colSize">Size of the col.</param>
        /// <param name="isPrimaryKey">if set to <c>true</c> [is primary key].</param>
        /// <param name="isUseSysDate">if set to <c>true</c> [is use database system date].</param>
        /// <param name="isParseUpdate">if set to <c>true</c> [is parse update].</param>
        /// <param name="isUseDbSequence">if set to <c>true</c> [is use db sequence].</param>
        /// <param name="isParseInsert">if set to <c>true</c> [is parse insert].</param>
        protected DbColumn(string colName, object dbType, ushort colSize, bool isPrimaryKey, bool isUseSysDate, bool isParseUpdate, bool isUseDbSequence, bool isParseInsert)
            : this(colName, dbType, colSize, isPrimaryKey, isUseSysDate, isParseUpdate, isUseDbSequence)
        {
            this.IsParseInsert = isParseInsert;
        }

        /// <summary>
        /// Gets the name of the colum.
        /// </summary>
        /// <value>The name of the colum.</value>
        public string ColumName { get; private set; }

        /// <summary>
        /// Gets the size of the colum.
        /// </summary>
        /// <value>The size of the colum.</value>
        public ushort ColumSize { get; private set; }

        /// <summary>
        /// Gets the type of the db.
        /// </summary>
        /// <value>The type of the db.</value>
        public object DbType { get; private set; }

        /// <summary>
        /// Gets a value indicating whether this instance is primary key.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance is primary key; otherwise, <c>false</c>.
        /// </value>
        public bool IsPrimaryKey { get; protected set; }

        /// <summary>
        /// Gets a value indicating whether this instance is use system date.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance is use sys date; otherwise, <c>false</c>.
        /// </value>
        public bool IsUseSysDate { get; private set; }

        /// <summary>
        /// Gets a value indicating whether this instance is parse update.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance is parse update; otherwise, <c>false</c>.
        /// </value>
        public bool IsParseUpdate { get; private set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is use db sequence.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance is use db sequence; otherwise, <c>false</c>.
        /// </value>
        public bool IsUseDbSequence { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is parse insert.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance is parse insert; otherwise, <c>false</c>.
        /// </value>
        public bool IsParseInsert { get; private set; }

        /// <summary>
        /// Gets a value indicating whether this instance is parse select.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance is parse select; otherwise, <c>false</c>.
        /// </value>
        public bool IsParseSelect { get; internal set; }
    }
}